var app;
String.prototype.trim=function(){
    return this.replace(/(^\s*)|(\s*$)/g, "");
};
jQuery(document).ready(function(){
	app = new Vue({
        el: '#app',
        data: {
            logFileForm :{
            	logPathType : 'absolute',
            	logPath : '',
            	logNumReadType : 'linkRead',
            	logNumRead : 1000,
            	logText : ''
            }
        },
        methods: {
            showLog : function (){
            	loadLogText();
            }
        },
        created: function(){
        	var o = ajaxJson("/mobile/plugin/westvalley/tools/log/jsp/ajaxDefaultLogPath.jsp",{});
        	if(o){
        		this.logFileForm.logPath = o.defaultLogPath;
        	}
        }
    });
	loadLogText();
});

function loadLogText(){
	var url = "/mobile/plugin/westvalley/tools/log/jsp/ajaxLoadLogFile.jsp";
	jQuery.ajax({
		type : "POST",
		url : url,
		data : {
			logPath : app.logFileForm.logPath,
			numRead : app.logFileForm.logNumRead
		},
		dataType : "text",
		async : false,
		success : function(data) {
			app.logFileForm.logText = data.trim();
		},
		error: function(x,msg){
			alert(msg);
		}
	});
}


/**
 * 异步提交
 * @param url
 * @param data
 * @returns json
 */
function ajaxJson(url, data) {
	var datas = "";
	jQuery.ajax({
		type : "POST",
		url : url,
		data : data,
		dataType : "json",
		async : false,
		success : function(data) {
			datas = data;
		},
		error: function(x,msg){
			alert(msg);
		}
	});
	return datas;
}